package org.darkforest.model;

import java.math.BigDecimal;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.darkforest.common.util.DateUtil;
import org.darkforest.common.util.JSONUtils;
import org.darkforest.enums.OrderPayTypeEnum;
import org.darkforest.enums.OrderStatusEnum;

/**
 * 
 * 项目名称         :bwmall-common
 * 文件名           :OrderVo.java
 * 开发公司及作者    :陈超
 * 版本号及开发日期  :Rev. 1.00 (2015年2月8日)
 */
public class OrderVo extends Order {
	
    private String addTimeStr;

    private String paymentTimeStr;

    private String shippingTimeStr;
    
    private String finnshedTimeStr;
    
    private List<OrderGoods> goods;
    
    private OrderCommonVo common;
    
    private OrderPay pay;

    private DAddress daddress;

	private Address address;
    
    private Store store;
    
    private String cancelType;
    private String cancelText;

	private boolean if_receive;			//是否可以收货标志位（订单状态30，且无退款操作）
	private boolean if_cancel;			//是否可取消标志位（）
	private boolean if_deliver;			//是否可以查看物流标志（订单状态为30，且物流单号不为空）
	private String mobPhone;

	private  List<OrderGiftCode> orderGiftCodes;  //礼品码
	private GiftPackage giftPackage;  //包装
	private GiftCardTemplate giftCardTemplate;  //卡片
	private List<GiftDistribution> giftDistributionList;  //快递定制

    public OrderVo() {
    }

    public boolean getIf_receive() {
		if("30".equals(getOrderState())){
			return true;
		}
		return false;
	}

	public boolean getIf_cancel() {
		if("10".equals(getOrderState())){
			return true;
		}
		return false;
	}

	public boolean getIf_deliver() {
		if("30".equals(getOrderState()) && StringUtils.isNotEmpty(getShippingCode())){
			return true;
		}
		return false;
	}

	public String getPaymentCodeStr(){
    	OrderPayTypeEnum type = OrderPayTypeEnum.getByValue(super.getPaymentCode());
    	if(type == null){
    		return "";
    	}
    	return type.getText();
    }


	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}


	public String getAddTimeStr() {
		return addTimeStr;
	}

	public void setAddTimeStr(String addTimeStr) {
		this.addTimeStr = addTimeStr;
	}

	public List<OrderGoods> getGoods() {
		return goods;
	}



	public void setGoods(List<OrderGoods> goods) {
		this.goods = goods;
	}

	
	public int getGoodsSize(){
		return goods.size() == 0 ? 1 : goods.size();
	}
	
	


	public String getPaymentTimeStr() {
		return paymentTimeStr;
	}



	public void setPaymentTimeStr(String paymentTimeStr) {
		this.paymentTimeStr = paymentTimeStr;
	}

	
	


	public String getFinnshedTimeStr() {
		if(this.getFinnshedTime()<1) return "";
		return finnshedTimeStr;
	}



	public void setFinnshedTimeStr(String finnshedTimeStr) {
		this.finnshedTimeStr = finnshedTimeStr;
	}


	

	public OrderCommonVo getCommon() {
		return common;
	}



	public void setCommon(OrderCommonVo common) {
		this.common = common;
	}

	
	

	public OrderPay getPay() {
		return pay;
	}



	public void setPay(OrderPay pay) {
		this.pay = pay;
	}
	
	



	public Store getStore() {
		return store;
	}



	public void setStore(Store store) {
		this.store = store;
	}

	
	


	public String getCancelType() {
		return cancelType;
	}



	public void setCancelType(String cancelType) {
		this.cancelType = cancelType;
	}



	public String getCancelText() {
		return cancelText;
	}



	public void setCancelText(String cancelText) {
		this.cancelText = cancelText;
	}

	


	public String getMobPhone() {
		return mobPhone;
	}

	public void setMobPhone(String mobPhone) {
		this.mobPhone = mobPhone;
	}

	public String getOrderStateStr(){
		OrderStatusEnum e= OrderStatusEnum.getByValue(super.getOrderState());
		if(e == null){
			return e.getText();
		}
		return e.getText();
	}

    public String getShippingTimeStr() {
        return shippingTimeStr;
    }

    public void setShippingTimeStr(String shippingTimeStr) {
        this.shippingTimeStr = shippingTimeStr;
    }



    public String getCloseTime(){
        return DateUtil.toIntDateString(super.getAddTime() + 24*60*60);
    }


    public DAddress getDaddress() {
        return daddress;
    }

    public void setDaddress(DAddress daddress) {
        this.daddress = daddress;
    }

	public String getGoodIds(){
		StringBuilder goodsIds = new StringBuilder();
		if(goods.size()>0){
			for(OrderGoods gs:goods){
				goodsIds.append(gs.getGoodsId()+",");
			}
			return goodsIds.substring(0, goodsIds.lastIndexOf(",")).toString();

		}else{
			return "";
		}
	}

	public List<OrderGiftCode> getOrderGiftCodes() {
		return orderGiftCodes;
	}

	public void setOrderGiftCodes(List<OrderGiftCode> orderGiftCodes) {
		this.orderGiftCodes = orderGiftCodes;
	}

	public GiftPackage getGiftPackage() {
		String giftPackageStr =common!=null&&common.getGiftPackage()!=null?common.getGiftPackage():"";
		if(giftPackageStr!=null&&!giftPackageStr.equals("")) {
			giftPackage = JSONUtils.toBean(giftPackageStr, GiftPackage.class);
		}
		return giftPackage;
	}

	public void setGiftPackage(GiftPackage giftPackage) {
		this.giftPackage = giftPackage;
	}

	public GiftCardTemplate getGiftCardTemplate() {
		String giftCardStr = common!=null&&common.getGiftCart()!=null?common.getGiftCart(): "";
		if(giftCardStr!=null&&!giftCardStr.equals("")) {
			giftCardTemplate = JSONUtils.toBean(giftCardStr, GiftCardTemplate.class);
		}
		return giftCardTemplate;
	}

	public void setGiftCardTemplate(GiftCardTemplate giftCardTemplate) {
		this.giftCardTemplate = giftCardTemplate;
	}

	public List<GiftDistribution> getGiftDistributionList() {
		String giftDistributionStr = common!=null&&common.getGiftDistribution()!=null?common.getGiftDistribution(): "";
		if(giftDistributionStr!=null&&!giftDistributionStr.equals("")) {
			giftDistributionList = JSONUtils.toList(giftDistributionStr,GiftDistribution.class);
		}
		return giftDistributionList;
	}

	public void setGiftDistributionList(List<GiftDistribution> giftDistributionList) {
		this.giftDistributionList = giftDistributionList;
	}

	public BigDecimal getFee() {
		BigDecimal fee = new BigDecimal(0.00);
		if(giftPackage!=null)
			fee= fee.add(giftPackage.getPackagePrice());
		if(giftCardTemplate!=null)
			fee=fee.add(giftCardTemplate.getCardPrice());
		if(giftDistributionList!=null&&giftDistributionList.size()>1){
			for(GiftDistribution giftDistribution : giftDistributionList){
				fee= fee.add(giftDistribution.getDistributionItemPrice());
			}
		}
		return fee;
	}
}
